import student from '../../api/student'

const state = {
  studentInfo: {}
};

const mutations = {
  SET_STUDENT_INFO(state, data) {
    state.studentInfo = data;
  }
}

const actions = {

  /**
   * 创建学员
   * @param state
   * @param commit
   * @param params
   */
  async createStudent({state, commit}, params) {
    return await student.create(params);
  },

  async userLogin({state, commit}, params) {
    const ret = await student.login(params);
    return ret.data.data;
  },

  async getStudentInfo({state, commit}) {
    if (state.studentInfo) {
      return state.studentInfo;

    } else {
      const ret = await student.info();
      commit('SET_STUDENT_INFO', ret.data.data);

      return ret.data.data;
    }
  },

  async studentList({state, commit}, params) {
    let ret = await student.list(params);

    return ret.data.data;
  },

};

export default {
  namespaced: true,
  actions
}
